package com.tianruan.psychological.moduls.sys.user.service.impl;


import com.tianruan.psychological.moduls.sys.user.entry.db.UserRoleDO;
import com.tianruan.psychological.moduls.sys.user.mapper.UserRoleMapper;
import com.tianruan.psychological.moduls.sys.user.service.IUserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author: Dong
 * @Email: dong980514280@gmail.com
 * @Create: 2020-09-20 10:07
 * @PS
 */
@Service("userRoleService")
public class UserRoleServiceImpl implements IUserRoleService {


    @Autowired
    private UserRoleMapper userRoleMapper;

    @Transactional
    public void insertUserRole(String userId, List<String> roleIdList){
        userRoleMapper.deleteByUserId(userId);
        roleIdList.stream()
                .map(roleId->new UserRoleDO().setUserId(userId).setRoleId(roleId))
                .forEach(userRole->userRoleMapper.insert(userRole));
    }
}
